package com.hj.tools;

import cn.hutool.core.io.FileUtil;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @author < a href="huajian2018@aliyun.com">hj</ a>
 * @Description 二维码生成,保存到 cos 存储
 */
@Component
public class QrCodeUtil {

    private final TenCentCloudUtil tenCentCloudUtil;

    public QrCodeUtil(TenCentCloudUtil tenCentCloudUtil) {
        this.tenCentCloudUtil = tenCentCloudUtil;
    }

    /**
     * 生成二维码,保存到文件服务器,返回存储路径
     * @param content 内容
     * @return 路径
     */
    public String createQrCode(String content) {
        String str = System.getProperty("user.dir");
        String path = str + "/qrCode.jpg";
        File file = cn.hutool.extra.qrcode.QrCodeUtil.generate(content, 300, 300, FileUtil.file(path));
        String s = tenCentCloudUtil.cosUpload(file);
        System.err.println(s);
        System.out.println(s);
        System.err.println(s);
        return s;
    }

}
